package main

import (
	"ginweb/account"
	"ginweb/class"
	"ginweb/dashboard"
	"github.com/gin-gonic/gin"
	"io/ioutil"
)

func main() {
	gin.SetMode(gin.ReleaseMode)
	gin.DefaultWriter = ioutil.Discard

	r := gin.Default()

	r.Static("/source", "source")

	r.LoadHTMLGlob("html/*")

	r.GET("/version", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"version": "v1.0",
		})
	})

	r.GET("/", account.Login)

	r.GET("/login", account.Login)
	r.POST("/login", account.LoginIn)

	r.GET("/dashboard", dashboard.Dashboard)

	r.GET("/class/list", class.List)
	r.GET("/class/add", class.Add)

	r.POST("/class/insert", class.Insert)

	r.POST("/login-out", account.LoginOut)

	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})

    listen_port := ":8888"

    r.Run(listen_port) // 默认r.Run()监听并在 0.0.0.0:8080 上启动服务
}
